package com.blank.web.servlet;

import com.blank.web.bean.ClassBean;
import com.blank.web.service.ClassService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "searchClassServlet",urlPatterns = "/searchClass")
public class searchClassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符编码
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        ClassService classService = new ClassService();
        List<ClassBean> classList = classService.searchClassByName(name);
        //将classList存入到request请求中
        request.setAttribute("list",classList);
        request.getRequestDispatcher("showClassInfo.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
